#!/bin/bash
menu(){
    echo "1、监控内存使用情况,如果内存使用率大于百分之80，给予提醒"
    echo "2、扫描局域网ip,检查哪些ip地址正在使用"
    echo "3、监控文件/etc/passwd是否被修改，每隔5分钟监控一次"
    echo "4、监控nginx进程是否存在，不存在就给予相应提醒"
}
menu
read -p "请输入你的选项: " option
case $option in
1)
    total=`free -m|grep -i mem|tr -s " "|cut -d " " -f2`
    used=`free -m|grep -i mem|tr -s " "|cut -d " " -f3`
    used_rate=`echo "scale=4;$used/$total" |bc`
    result=` echo "$used_rate>0.8"|bc `
    if (( $result  == 1 ))
    then
        echo -e "\e[31m使用率超过80%，请及时对内存扩容，以免不必要的损
失\e[0m"
    else
        echo  " nothing to do"
    fi
    ;;
2)
    for ip in 192.168.138.{1..255}
    do
        (
        ping -c 1 $ip &>/dev/null && echo $ip >>up.txt || echo $ip >> down.txt
        ) &
    done
    wait
    ;;
3)
    dif=`diff /etc/passwd /root/lianxi/passwd |wc -l`
    [[$dif -eq 0]] && echo "文件未被修改" || echo "文件已被修改"
    ;;
4)
    pidof nginx && echo "nginx is running" || echo "nginx is down"
    #if [[$? -eq 0]]
    #then
    #    echo "nginx is running"
    #fi
    ;;
*)
    echo "请输入指定内容1-4！"
esac

